< previous page page_597 next page >

Page 597
e10a6a0a59f035e870d90cca05b85fce.gif
                 End With 
             Else
                 pic.Line (pix_x, pix_y)- _ 
                     Step(skip - 1, skip - 1), _
                     RGB(R, G, B), BF 
             End If
        Next pix_x

         ' Let the user see what's going on.
         If skip < 2 Then 
             pic.Line (pic.ScaleLeft, pix_y)-(Xmax, pix_y), _ 
                 vbWhite 
         Else
             pic.Refresh
         End If

        ' If the Stop button was pressed, stop.
        DoEvents
        If Not Running Then Exit Sub 
    Next pix_y

    If skip < 2 Then
        SetBitmapPixels pic, bits_per_pixel, pixels
    End If
End Sub
Performance
As you might imagine, ray tracing can be slow. Ray tracing even a simple scene can require many calculations. For a 300 by 300 pixel image containing four spheres, the program must compute the color for 90,000 pixels.
For each of those pixels, it uses the FindT function to determine the distance between the center of projection and each of the four spheres in the scene. The FindT function involves roughly 34 multiplications and divisions, 29 additions and subtractions, and even two square roots. Assuming the ray through a pixel strikes some object in the scene, you also need to add about 100 more operations to compute the pixel's color using the FindHitColor and CalculateHitColor functions. The total number of operations needed to display the four spheres is roughly:
e10a6a0a59f035e870d90cca05b85fce.gif
(90,000 pixels) *
[(65 operations per FindT) * (4 spheres) +
 (100 operations per FindHitColor)]
» 32 million operation
This does not take into account all the overhead of making 4 * 90,000 = 360,000 calls to function FindT and as many as 90,000 calls to function FindHitColor and CalculateHitColor. All of these calculations add up to make ray tracing quite slow.

 
< previous page page_597 next page >